package cn.wyl.service.impl;

import cn.wyl.Product;
import cn.wyl.Store;
import cn.wyl.feignclient.StoreFeignClient;
import cn.wyl.mapper.ProductMapper;
import cn.wyl.result.JsonResult;
import cn.wyl.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class ProductServiceImpl implements IProductService {
    @Autowired
    private ProductMapper productMapper;

    @Autowired
    private StoreFeignClient storeFeignClient;

    @Transactional
    @Override
    public void add(Product product) {

            productMapper.add(product);
            Long number = product.getNumber();
            Long productId = product.getId();
            Store store = new Store(null,productId, number);
            JsonResult result = storeFeignClient.add(store);
            if (!result.isSuccess()){
                throw new RuntimeException(result.getMessage());
            }


    }
}
